Cuba

Author

Liwen Yin

library(rnaturalearth)
library(sf)
Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
library(dplyr)

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
library(tmap)
Warning: package 'tmap' was built under R version 4.4.2

Attaching package: 'tmap'
The following object is masked from 'package:datasets':

    rivers
library(leaflet)

#Discription of Cuba

#word data
land <- st_read("ne_10m_land/ne_10m_land.shp")
Reading layer `ne_10m_land' from data source 
  `/Users/vivien/Desktop/MSSP/615/615Final/615Final/ne_10m_land/ne_10m_land.shp' 
  using driver `ESRI Shapefile'
Simple feature collection with 11 features and 3 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: -180 ymin: -90 xmax: 180 ymax: 83.6341
Geodetic CRS:  WGS 84
if (is.na(st_crs(land))) {
  st_crs(land) <- 4326
}
#cuba area
cuba_extent <- st_bbox(c(xmin = -85, ymin = 19, xmax = -74, ymax = 24), crs = st_crs(land))
land <- st_transform(land, crs = 4326)

cuba <- st_crop(land, cuba_extent)
Warning: attribute variables are assumed to be spatially constant throughout
all geometries
physical_labels <- st_read("ne_50m_geography_regions_points/ne_50m_geography_regions_points.shp")
Reading layer `ne_50m_geography_regions_points' from data source 
  `/Users/vivien/Desktop/MSSP/615/615Final/615Final/ne_50m_geography_regions_points/ne_50m_geography_regions_points.shp' 
  using driver `ESRI Shapefile'
Simple feature collection with 162 features and 39 fields
Geometry type: POINT
Dimension:     XY
Bounding box:  xmin: -173.9767 ymin: -75.59185 xmax: 179.1984 ymax: 83.62629
Geodetic CRS:  WGS 84
physical_labels <- st_transform(physical_labels, st_crs(cuba))

cuba_extent_sf <- st_as_sfc(cuba_extent)

cuba_labels <- physical_labels[st_intersects(physical_labels, cuba_extent_sf, sparse = FALSE), ]
#cuba map
map_cuba <- tm_shape(cuba) +
  tm_polygons(col = "skyblue", border.col = "black") +
  tm_layout(
    title = "Cuba land",
    title.size = 1,
    title.position = c("left", "top"),
    legend.outside = TRUE
  )
── tmap v3 code detected ───────────────────────────────────────────────────────
[v3->v4] `tm_polygons()`: use 'fill' for the fill color of polygons/symbols
(instead of 'col'), and 'col' for the outlines (instead of 'border.col').
[v3->v4] `tm_layout()`: use 'tm_title()' instead of `tm_layout(title = )`
This message is displayed once every 8 hours.
#cuba on world map
map_world <- tm_shape(land) +
  tm_polygons(col = "lightgray", border.col = "white") +  
  tm_shape(cuba) +
  tm_polygons(col = "red", border.col = "black") +  
  tm_layout(
    title = "Cuba's Location on World Map",
    title.size = 1,
    title.position = c("left", "top")
  )
[v3->v4] `tm_layout()`: use 'tm_title()' instead of `tm_layout(title = )`
tmap_arrange(map_cuba, map_world)  

#world interaction
world_map <- leaflet() %>%
  addProviderTiles("CartoDB.Positron") %>%
  addPolygons(
    data = land,
    fillColor = "lightgray",
    color = "white",
    weight = 0.5,
    fillOpacity = 0.7,
    popup = ~"World Map"
  ) %>%
  addPolygons(
    data = cuba,
    fillColor = "red",
    color = "black",
    weight = 1,
    fillOpacity = 0.8,
    popup = ~"Cuba"
  ) %>%
  addCircleMarkers(
    lng = -80,
    lat = 21.5,
    radius = 8,
    color = "blue",
    fillColor = "blue",
    fillOpacity = 1,
    popup = "Cuba Center"
  )
#cuba interaction
cuba_map <- leaflet() %>%
  addProviderTiles("CartoDB.Positron") %>%
  addPolygons(
    data = cuba,
    fillColor = "skyblue",
    color = "black",
    weight = 1,
    fillOpacity = 0.6,
    popup = ~"Cuba Land"
  )

cuba_map
world_map